<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib uri="/WEB-INF/tld/pageutil.tld" prefix="pu"%>
<%@taglib uri="/WEB-INF/tld/pageable.tld" prefix="pageable"%>
<%@taglib uri="http://java.sun.com/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jstl/core_rt" prefix="c-rt"%>
<%@taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt-rt"%>
<script language="javascript">
$(function(){
	$('#submitButton').click(function(){
		$('#manager > option').each(function(){
			$(this).attr('selected', 'selected');
		});
		$('#approver > option').each(function(){
			$(this).attr('selected', 'selected');
		});
		$('#observer > option').each(function(){
			$(this).attr('selected', 'selected');
		});
		$('#member > option').each(function(){
			$(this).attr('selected', 'selected');
		});
		document.groupUserForm.submit();
	});
});

function move(fbox, tbox) {
var arrFbox = new Array();
var arrTbox = new Array();
var arrLookup = new Array();
var i;
for (i = 0; i < tbox.options.length; i++) {
arrLookup[tbox.options[i].text] = tbox.options[i].value;
arrTbox[i] = tbox.options[i].text;
}
var fLength = 0;
var tLength = arrTbox.length;
for(i = 0; i < fbox.options.length; i++) {
arrLookup[fbox.options[i].text] = fbox.options[i].value;
if (fbox.options[i].selected && fbox.options[i].value != "") {
arrTbox[tLength] = fbox.options[i].text;
tLength++;
}
else {
arrFbox[fLength] = fbox.options[i].text;
fLength++;
   }
}
//arrFbox.sort();
//arrTbox.sort();
fbox.length = 0;
tbox.length = 0;
var c;
for(c = 0; c < arrFbox.length; c++) {
var no = new Option();
no.value = arrLookup[arrFbox[c]];
no.text = arrFbox[c];
fbox[c] = no;
}
for(c = 0; c < arrTbox.length; c++) {
var no = new Option();
no.value = arrLookup[arrTbox[c]];
no.text = arrTbox[c];
tbox[c] = no;
   }
}

</script>
${pu:reqSet('hql', 'from TaskGroupUser where taskGroup.id=? and taskRole=?') }
${pu:listAdd('theparams', param.taskGroupId) }
${pu:listAdd('theparams', 'MANAGER') }
${pu:reqSet('managers', pu:queryByHql(hql, pu:arrayGet('theparams'), null)) }
${pu:reqSet('theparams', null) }
${pu:listAdd('theparams', param.taskGroupId) }
${pu:listAdd('theparams', 'APPROVER') }
${pu:reqSet('approvers', pu:queryByHql(hql, pu:arrayGet('theparams'), null)) }
${pu:reqSet('theparams', null) }
${pu:listAdd('theparams', param.taskGroupId) }
${pu:listAdd('theparams', 'OBSERVER') }
${pu:reqSet('observers', pu:queryByHql(hql, pu:arrayGet('theparams'), null)) }
${pu:reqSet('theparams', null) }
${pu:listAdd('theparams', param.taskGroupId) }
${pu:listAdd('theparams', 'MEMBER') }
${pu:reqSet('members', pu:queryByHql(hql, pu:arrayGet('theparams'), null)) }

${pu:reqSet('taskGroup', pu:get('com.yaodian100.crm.workorder.entity.TaskGroup', param.taskGroupId)) }
<div class="f-link"><a href="/ecadmin/cs/taskGroup/page.do?iamlazy=list" id="list">任務群組管理</a></div>
<div class="f-link"><a href="/ecadmin/cs/taskGroup/page.do?iamlazy=userList" id="userList">使用者列表</a></div>

<h1>任務群組分派（${taskGroup.name }）</h1>
${message }
<form name="groupUserForm" method="post" action="/ecadmin/cs/taskGroup/updateGroupUser.do">
<input type="hidden" name="taskGroupId" value="${param.taskGroupId }"/>
<input type="hidden" name="id" value="${param.taskGroupId }"/>
<table class="tb-data" width="100%">
<tr><th width="250">未指定</th><td width="60"></td><td>角色</td></tr>
<tr><th rowspan="5">
${pu:reqSet('users', pu:queryByHql('from User order by username asc', null, null)) }

<c-rt:forEach items="${users}" var="user">
	${pu:reqSet('isExist', false) }
	<c-rt:forEach items="${managers }" var="manager">
	<c-rt:if test="${user.username==manager.user.username}">
	${pu:reqSet('isExist', true) }
	</c-rt:if>
	</c-rt:forEach>
	<c-rt:if test="${!isExist}">
	${pu:listAdd('allUsers', user) }
	</c-rt:if>
</c-rt:forEach>
<c-rt:forEach items="${allUsers}" var="user">
	${pu:reqSet('isExist', false) }
	<c-rt:forEach items="${approvers }" var="approver">
	<c-rt:if test="${user.username==approver.user.username}">
	${pu:reqSet('isExist', true) }
	</c-rt:if>
	</c-rt:forEach>
	<c-rt:if test="${!isExist}">
	${pu:listAdd('allUsers2', user) }
	</c-rt:if>
</c-rt:forEach>
<c-rt:forEach items="${allUsers2}" var="user">
	${pu:reqSet('isExist', false) }
	<c-rt:forEach items="${observers }" var="observer">
	<c-rt:if test="${user.username==observer.user.username}">
	${pu:reqSet('isExist', true) }
	</c-rt:if>
	</c-rt:forEach>
	<c-rt:if test="${!isExist}">
	${pu:listAdd('allUsers3', user) }
	</c-rt:if>
</c-rt:forEach>
<c-rt:forEach items="${allUsers3}" var="user">
	${pu:reqSet('isExist', false) }
	<c-rt:forEach items="${members }" var="member">
	<c-rt:if test="${user.username==member.user.username}">
	${pu:reqSet('isExist', true) }
	</c-rt:if>
	</c-rt:forEach>
	<c-rt:if test="${!isExist}">
	${pu:listAdd('allUsers4', user) }
	</c-rt:if>
</c-rt:forEach>

<select name="all" multiple="multiple" size="35" style="width:250px">
<c-rt:forEach items="${allUsers4 }" var="user">
<option value="${user.username }">${user.username }  ${user.nameNative}-${user.groupName }</option>
</c-rt:forEach>
</select>
</th><td><br/><input type="button" onclick="move(this.form.manager,this.form.all)" value="&lt;"/> <input type="button" onclick="move(this.form.all,this.form.manager)" value="&gt;"/></td>
<td>管理者<br/><select id="manager" name="manager" multiple="multiple" size="8" style="width:250px">
<c-rt:forEach items="${managers}" var="manager">
<option value="${manager.user.username}">${manager.user.username } ${manager.user.nameNative}-${manager.user.groupName }</option>
</c-rt:forEach>
</select></td></tr>
<%--
<tr><td><input type="button" onclick="move(this.form.approver,this.form.all)" value="&lt;"/> <input type="button" onclick="move(this.form.all,this.form.approver)" value="&gt;"/></td>
<td>审核者<br/><select id="approver" name="approver" multiple="multiple" size="8" style="width:250px">
<c-rt:forEach items="${approvers}" var="approver">
<option value="${approver.user.username}">${approver.user.username }-${approver.user.groupName }</option>
</c-rt:forEach>
</select></td></tr>
<--%>
<tr><td><input type="button" onclick="move(this.form.observer,this.form.all)" value="&lt;"/> <input type="button" onclick="move(this.form.all,this.form.observer)" value="&gt;"/></td>
<td>观察者<br/><select id="observer" name="observer" multiple="multiple" size="8" style="width:250px">
<c-rt:forEach items="${observers}" var="observer">
<option value="${observer.user.username}">${observer.user.username } ${observer.user.nameNative}-${observer.user.groupName }</option>
</c-rt:forEach>
</select></td></tr>
<tr><td><input type="button" onclick="move(this.form.member,this.form.all)" value="&lt;"/> <input type="button" onclick="move(this.form.all,this.form.member)" value="&gt;"/></td>
<td>成员<br/><select id="member" name="member" multiple="multiple" size="8" style="width:250px">
<c-rt:forEach items="${members}" var="member">
<option value="${member.user.username}">${member.user.username } ${member.user.nameNative}-${member.user.groupName }</option>
</c-rt:forEach>
</select></td></tr>
<tr><td></td><td><input type="button" id="submitButton" value="送出"/><input type="button" onclick="location.href='/ecadmin/cs/taskGroup/page.do?iamlazy=toUpdateGroupUser&taskGroupId=${param.taskGroupId}'" value="重置"/></td></tr>
</table>
</form>